package misp_backend.controller;

import misp_backend.config.AjaxResult;
import misp_backend.domain.Category;
import misp_backend.domain.Dishes;
import misp_backend.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @GetMapping("/all")
    public AjaxResult listAllCategory(){
        return AjaxResult.success(categoryService.list());
    }
    @PostMapping("/add")
    public AjaxResult addNewCategory(@RequestBody Category category){
        Date time=new Date();
        category.setCreateTime(time);
        return AjaxResult.success(categoryService.save(category));
    }
    @PostMapping("/update")
    public AjaxResult updateDish(@RequestBody Category category){
        Date time=new Date();
        category.setUpdateTime(time);
        return AjaxResult.success(categoryService.updateById(category));
    }
    @DeleteMapping("/remove")
    public AjaxResult removeDish(@RequestParam Long categoryid){
        return AjaxResult.success(categoryService.removeById(categoryid));

    }
}
